package com.lcu.wl.modules.tools.controller;

import com.lcu.wl.annotation.Log;
import com.lcu.wl.common.utils.PageUtils;
import com.lcu.wl.common.utils.SYSDATA;
import com.lcu.wl.modules.tools.entity.QuartzLog;
import com.lcu.wl.modules.tools.service.IQuartzLogService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 定时任务日志 前端控制器
 * </p>
 *
 * @author wanglei
 * @since 2021-03-18
 */
@RestController
@RequestMapping("/tools/quartz-log")
public class QuartzLogController {

    @Autowired
    private IQuartzLogService iQuartzLogService;

    /**
     * 定时任务日志列表
     */
    @GetMapping("/list")
    @ApiOperation("定时任务日志查询")
    @RequiresPermissions("tools:quartz:log:list")
    public SYSDATA list(@RequestParam Map<String, Object> params){
        PageUtils page = iQuartzLogService.queryPage(params);
        return SYSDATA.ok().put("page", page);
    }

    /**
     * 导出定时任务日志数据
     * @param params
     * @param response
     * @throws IOException
     */
    @Log("导出定时任务日志数据")
    @ApiOperation("定时任务日志导出")
    @GetMapping("/download")
    @RequiresPermissions("tools:quartz:log:export")
    public void download(@RequestParam Map<String,Object> params, HttpServletResponse response) throws IOException {
        List<QuartzLog> quartzLogList = iQuartzLogService.queryAll(params);
        iQuartzLogService.download(quartzLogList,response);
    }

    /**
     * 获取执行定时任务日志异常信息详情
     * @param logId
     * @return
     */
    @GetMapping("/info/{logId}")
    @ApiOperation("根据logId查询定时任务日志异常信息详情")
    @RequiresPermissions("tools:quartz:log:info")
    public SYSDATA info(@PathVariable Long logId){
        QuartzLog errDetail = iQuartzLogService.getById(logId);
        return SYSDATA.ok().put("errDetail",errDetail);
    }


}
